package org.jeecg.service.service;

import org.jeecg.domain.Goods;
import org.jeecg.mapper.GoodsMapper;
import org.jeecg.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;


    @Override
    public List<Goods> getAllGoods() {
        List<Goods> goods = goodsMapper.queryAll();
        return goods;
    }

    /**
     * 发布商品
     * @param goods
     * @return
     */
    @Override
    public Boolean add(Goods goods) {
        UUID uuid = UUID.randomUUID();
        //生成一个16位的UUID
        String id = uuid.toString().replace("-","").substring(0,16);
        goods.setId(id);
        try {
            goodsMapper.insertGoods(goods);
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
        return true;
    }

    @Override
    public Goods queryGoods(String goodId) {
        Goods goods = goodsMapper.queryGoods(goodId);
        return goods;
    }
}
